package com.adams.action.sys;

import com.adams.common.BaseAction;
import com.adams.common.Certificate;
import com.adams.common.Constants;

/**
 * 
 * 
 * File Name : LoginAction.java
 * 
 * @Description : 系统登录类
 * @author 902990封文进
 */
public class LoginAction extends BaseAction
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4767410429064110235L;

	private String userName;

	private String password;

	private String validateCode;

	/**
	 * 
	 * Description : 登录
	 * 
	 * @return String
	 * 
	 */
	public String login()
	{

		request.setAttribute("userName", userName);

		// 参数校验
		// 用户名不能为空
		if (userName == null || "".equals(userName.trim()))
		{
			request.setAttribute("msg", Constants.LOGIN_FAIL_USER_NULL);
			return ERROR;
		}

		// 密码不能为空
		if (password == null || "".equals(password.trim()))
		{
			request.setAttribute("msg", Constants.LOGIN_FAIL_PASSWD_NULL);
			return ERROR;
		}

		// 根据用户名和密码创建证书(验证码校验、密码检测、角色检测、获得权限资源)
		boolean isSuccess = Certificate.create(request, userName, password,
				validateCode);
		if (!isSuccess)
		{
			return ERROR;
		}
		createLog("loginSystem", "user name:" + userName);
		return SUCCESS;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public void setValidateCode(String validateCode)
	{
		this.validateCode = validateCode;
	}

}
